<template>
  <div>
    <el-button type="primary" @click="onTest">测试</el-button>
    <div v-for="post in posts" :key="post">
      <p v-show="post.show">{{ post.id }}</p>
    </div>
  </div>
</template>

<script>
import axios from 'axios';

export default {
  name: 'TestView',
  data() {
    return {
      posts: [{
        id: '(A,V1,T,40)',
        val: ['A', 'V1', 'T', '40'],
        show: false,
      }, {
        id: '(A,V2,T,30)',
        val: ['A', 'V2', 'T', '30'],
        show: false,
      }, {
        id: '(A,V3,F,100)',
        val: ['A', 'V3', 'F', '100'],
        show: false,
      }, {
        id: '(A,V4,F,120)',
        val: ['A', 'V4', 'F', '120'],
        show: false,
      }, {
        id: '(A,V2,O,0)',
        val: ['A', 'V2', 'O', '0'],
        show: false,
      }, {
        id: '(A,V5,T,20)',
        val: ['A', 'V5', 'T', '20'],
        show: false,
      }, {
        id: '(A,V6,T,20)',
        val: ['A', 'V6', 'T', '20'],
        show: false,
      }, {
        id: '(A,V7,F,110)',
        val: ['A', 'V7', 'F', '110'],
        show: false,
      }, {
        id: '(A,V8,T,20)',
        val: ['A', 'V8', 'T', '20'],
        show: false,
      }, {
        id: '(A,V9,F,105)',
        val: ['A', 'V9', 'F', '105'],
        show: false,
      }, {
        id: '(A,V10,T,10)',
        val: ['A', 'V10', 'T', '10'],
        show: false,
      }, {
        id: '(A,V11,F,110)',
        val: ['A', 'V11', 'F', '110'],
        show: false,
      }, {
        id: '(A,V12,F,90)',
        val: ['A', 'V12', 'F', '90'],
        show: false,
      }, {
        id: '(A,V13,F,110)',
        val: ['A', 'V13', 'F', '110'],
        show: false,
      }, {
        id: '(A,V14,F,95)',
        val: ['A', 'V14', 'F', '95'],
        show: false,
      }, {
        id: '(A,V15,T,10)',
        val: ['A', 'V15', 'T', '10'],
        show: false,
      }, {
        id: '(A,V16,F,60)',
        val: ['A', 'V16', 'F', '60'],
        show: false,
      }, {
        id: '(A,V17,T,10)',
        val: ['A', 'V17', 'T', '10'],
        show: false,
      }, {
        id: '(A,V18,T,7.5)',
        val: ['A', 'V18', 'T', '7.5'],
        show: false,
      }, {
        id: '(A,V19,F,75)',
        val: ['A', 'V19', 'F', '75'],
        show: false,
      }, {
        id: '(A,V20,F,95)',
        val: ['A', 'V20', 'F', '95'],
        show: false,
      }, {
        id: '(A,V21,F,95)',
        val: ['A', 'V21', 'F', '95'],
        show: false,
      }, {
        id: '(A,V22,F,70)',
        val: ['A', 'V22', 'F', '70'],
        show: false,
      }, {
        id: '(A,V23,F,80)',
        val: ['A', 'V23', 'F', '80'],
        show: false,
      }, {
        id: '(A,V24,T,5)',
        val: ['A', 'V24', 'T', '5'],
        show: false,
      }, {
        id: '(A,V25,T,15)',
        val: ['A', 'V25', 'T', '15'],
        show: false,
      }, {
        id: '(B,T1,O,0)',
        val: ['B', 'T1', 'O', '0'],
        show: false,
      }, {
        id: '(A,V26,T,20)',
        val: ['A', 'V26', 'T', '20'],
        show: false,
      }, {
        id: '(A,V27,T,25)',
        val: ['A', 'V27', 'T', '25'],
        show: false,
      }, {
        id: '(B,F1,O,0)',
        val: ['B', 'F1', 'O', '0'],
        show: false,
      }, {
        id: '(A,V28,F,30)',
        val: ['A', 'V28', 'F', '30'],
        show: false,
      }, {
        id: '(A,V1,O,0)',
        val: ['A', 'V1', 'O', '0'],
        show: false,
      }, {
        id: '(B,T1,O,1)',
        val: ['B', 'T1', 'O', '1'],
        show: false,
      }, {
        id: '(A,V27,O,0)',
        val: ['A', 'V27', 'O', '0'],
        show: false,
      }, {
        id: '(C,V21,F,35)',
        val: ['C', 'V21', 'F', '35'],
        show: false,
      }, {
        id: '(A,V19,O,0)',
        val: ['A', 'V19', 'O', '0'],
        show: false,
      }, {
        id: '(A,V28,O,0)',
        val: ['A', 'V28', 'O', '0'],
        show: false,
      }, {
        id: '(C,V23,F,40)',
        val: ['C', 'V23', 'F', '40'],
        show: false,
      }, {
        id: '(A,V29,T,30)',
        val: ['A', 'V29', 'T', '30'],
        show: false,
      }, {
        id: '(C,V14,F,30)',
        val: ['C', 'V14', 'F', '30'],
        show: false,
      }, {
        id: '(A,V30,T,10)',
        val: ['A', 'V30', 'T', '10'],
        show: false,
      }, {
        id: '(B,F1,O,1)',
        val: ['B', 'F1', 'O', '1'],
        show: false,
      }],
    };
  },
  methods: {
    change(i) {
      this.posts[i].show = true;
    },
    onTest() {
      const mythis = this;
      for (let i = 0; i < 42; i += 1) {
        setTimeout(() => {
          mythis.posts[i].show = true;
          let path = '';
          let form = {};
          if (mythis.posts[i].val[0] === 'A') {
            if (mythis.posts[i].val[3] === '0') {
              path = '/api/cancel_appoint';
              form = {
                id: mythis.posts[i].val[1],
              };
            } else {
              path = '/api/send_appoint';
              form = {
                id: mythis.posts[i].val[1],
                amount: parseFloat(mythis.posts[i].val[3]),
                mode: mythis.posts[i].val[2],
              };
            }
          } else if (mythis.posts[i].val[0] === 'B') {
            if (mythis.posts[i].val[3] === '0') {
              path = '/api/admin/station_failure';
            } else {
              path = '/api/admin/station_recovery';
            }
            form = {
              S_id: mythis.posts[i].val[1],
            };
          } else {
            path = '/api/change_appoint';
            form = {
              id: mythis.posts[i].val[1],
              amount: parseFloat(mythis.posts[i].val[3]),
              mode: mythis.posts[i].val[2],
            };
          }
          axios.post(path, form)
            .then((res) => {
              if (res.data.ok) {
                this.$message.success('发送成功');
              } else {
                this.$message.success('失败');
              }
            })
            .catch((error) => {
              // eslint-disable-next-line
              console.error(error);
            });
        }, i * 1000);
      }
      for (let i = 1; i < 350; i += 1) {
        setTimeout(() => {
          axios.post('/api/print', {})
            .then()
            .catch(() => {
            });
        }, i * 10000 + 42000);
      }
    },
  },
};
</script>

<style scoped>

</style>
